package com.fr.chart.axis;

import com.fr.base.XMLable;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.Title;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.ChartUtils;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Color;
import java.text.Format;

public abstract class Axis
  implements XMLable
{
  private static final long serialVersionUID = 3591400366172688862L;
  public static final String XML_TAG = "Axis";
  public static final int TICK_MARK_NONE = 0;
  public static final int TICK_MARK_INSIDE = 1;
  public static final int TICK_MARK_OUTSIDE = 2;
  public static final int TICK_MARK_CROSS = 3;
  protected int tickMarkType = 2;
  private int tickLength = 8;
  private int secTickMarkType = 1;
  private int secTickLength = 0;
  private float mainStroke = 1.0F;
  private float secStroke = 1.0F;
  public static final int LINE_LABEL_GAP = 4;
  public static final int LABEL_TITLE_GAP = 1;
  protected int position = 3;
  private Title title;
  private int mainGridStyle = 0;
  private Color mainGridColor = null;
  private int secondGridStyle = 0;
  private Color secondGridColor = null;
  protected Color lineColor = new Color(176, 176, 176);
  protected int lineStyle = 1;
  private TextAttr textAttr = new TextAttr();
  private Format format;
  private boolean isStagger = false;
  private int labelNumber = -1;
  private int axisLabelPosition = 3;
  private boolean isArrowShow = false;
  private boolean isAxisShow = true;
  private boolean isCustomMinValue = false;
  private double minValue = 0.0D;
  private boolean isCustomMaxValue = false;
  private double maxValue = 0.0D;

  public void setCustomMinValue(boolean paramBoolean)
  {
    this.isCustomMinValue = paramBoolean;
  }

  public boolean isCustomMinValue()
  {
    return this.isCustomMinValue;
  }

  public void setMinValue(double paramDouble)
  {
    this.minValue = paramDouble;
  }

  public double getMinValue()
  {
    return this.minValue;
  }

  public void setCustomMaxValue(boolean paramBoolean)
  {
    this.isCustomMaxValue = paramBoolean;
  }

  public boolean isCustomMaxValue()
  {
    return this.isCustomMaxValue;
  }

  public void setMaxValue(double paramDouble)
  {
    this.maxValue = paramDouble;
  }

  public double getMaxValue()
  {
    return this.maxValue;
  }

  public void setAxisShow(boolean paramBoolean)
  {
    this.isAxisShow = paramBoolean;
  }

  public boolean isAxisShow()
  {
    return this.isAxisShow;
  }

  public void setArrowShow(boolean paramBoolean)
  {
    this.isArrowShow = paramBoolean;
  }

  public boolean isArrowShow()
  {
    return this.isArrowShow;
  }

  public int getPosition()
  {
    return this.position;
  }

  public void setPosition(int paramInt)
  {
    this.position = paramInt;
  }

  public void setAxisLabelPosition(int paramInt)
  {
    this.axisLabelPosition = paramInt;
  }

  public int getAxisLabelPosition()
  {
    return this.axisLabelPosition;
  }

  public Title getTitle()
  {
    return this.title;
  }

  public void setTitle(Title paramTitle)
  {
    this.title = paramTitle;
  }

  public void setMainGridStyle(int paramInt)
  {
    this.mainGridStyle = paramInt;
  }

  public int getMainGridStyle()
  {
    return this.mainGridStyle;
  }

  public void setMainGridColor(Color paramColor)
  {
    this.mainGridColor = paramColor;
  }

  public Color getMainGridColor()
  {
    return this.mainGridColor;
  }

  public void setSecondGridStyle(int paramInt)
  {
    this.secondGridStyle = paramInt;
  }

  public int getSecondGridStyle()
  {
    return this.secondGridStyle;
  }

  public void setSecondGridColor(Color paramColor)
  {
    this.secondGridColor = paramColor;
  }

  public Color getSecondGridColor()
  {
    return this.secondGridColor;
  }

  public void setLabelNumber(int paramInt)
  {
    this.labelNumber = paramInt;
  }

  public int getLabelNumber()
  {
    return this.labelNumber;
  }

  public void setFormat(Format paramFormat)
  {
    this.format = paramFormat;
  }

  public Format getFormat()
  {
    return this.format;
  }

  public void setTextAttr(TextAttr paramTextAttr)
  {
    this.textAttr = paramTextAttr;
  }

  public TextAttr getTextAttr()
  {
    return this.textAttr;
  }

  public Color getLineColor()
  {
    return this.lineColor;
  }

  public void setLineColor(Color paramColor)
  {
    this.lineColor = paramColor;
  }

  public void setLineStyle(int paramInt)
  {
    this.lineStyle = paramInt;
  }

  public int getLineStyle()
  {
    return this.lineStyle;
  }

  public int getTickMarkType()
  {
    return this.tickMarkType;
  }

  public void setTickMarkType(int paramInt)
  {
    this.tickMarkType = paramInt;
  }

  public void setTickLength(int paramInt)
  {
    this.tickLength = paramInt;
  }

  public int getTickLength()
  {
    return this.tickLength;
  }

  public void setSecTickMarkType(int paramInt)
  {
    this.secTickMarkType = paramInt;
  }

  public void setMainStroke(float paramFloat)
  {
    this.mainStroke = paramFloat;
  }

  public float getMainStroke()
  {
    return this.mainStroke;
  }

  public void setSecStroke(float paramFloat)
  {
    this.secStroke = paramFloat;
  }

  public float getSecStroke()
  {
    return this.secStroke;
  }

  public int getSecTickMarkType()
  {
    return this.secTickMarkType;
  }

  public void setSecTickLength(int paramInt)
  {
    this.secTickLength = paramInt;
  }

  public int getSecTickLength()
  {
    return this.secTickLength;
  }

  public void setIsStagger(boolean paramBoolean)
  {
    this.isStagger = paramBoolean;
  }

  public boolean isStagger()
  {
    return this.isStagger;
  }

  public static double calculateIncrement(double paramDouble1, double paramDouble2)
  {
    double d1 = 1.0D;
    double d2 = 0.0D;
    d1 = (paramDouble2 - paramDouble1) / 3.0D;
    double d3 = 1.0D;
    if (d1 % 1.0D == 0.0D)
      return d1;
    if (d1 <= 1.0D)
    {
      d2 = Math.pow(10.0D, Math.ceil(Math.log(1.0D / d1) / Math.log(10.0D)));
      d3 = 1.0D / d2;
      d1 *= d2;
    }
    if (d1 > 10.0D)
    {
      d2 = Math.pow(10.0D, Math.ceil(Math.log(d1) / Math.log(10.0D)) - 1.0D);
      d3 = d2;
      d1 /= d2;
    }
    if (d1 <= 2.0D)
      d1 = 1.0D;
    else if (d1 <= 4.0D)
      d1 = 2.0D;
    else if (d1 <= 10.0D)
      d1 = 4.0D;
    d1 *= d3;
    return d1;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Axis localAxis = (Axis)super.clone();
    if (getTitle() != null)
      localAxis.setTitle((Title)getTitle().clone());
    if (getTextAttr() != null)
      localAxis.setTextAttr((TextAttr)getTextAttr().clone());
    if (getFormat() != null)
      localAxis.setFormat((Format)getFormat().clone());
    return localAxis;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2 = paramXMLableReader.getTagName();
      if (str2.equals("Title"))
      {
        Title localTitle = new Title();
        paramXMLableReader.readXMLObject(localTitle);
        setTitle(localTitle);
      }
      else
      {
        String str1;
        if ("TickLine".equals(str2))
        {
          if ((str1 = paramXMLableReader.getAttr("type")) != null)
            setTickMarkType(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("len")) != null)
            setTickLength(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("mainStroke")) != null)
            setMainStroke(Float.valueOf(str1).floatValue());
          if ((str1 = paramXMLableReader.getAttr("secType")) != null)
            setSecTickMarkType(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("secLen")) != null)
            setSecTickLength(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("secStroke")) != null)
            setSecStroke(Float.valueOf(str1).floatValue());
        }
        else if (str2.equals("AxisLabelCount"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
            setLabelNumber(Integer.parseInt(str1));
        }
        else if ("AxisLine".equals(str2))
        {
          if ((str1 = paramXMLableReader.getAttr("style")) != null)
            setLineStyle(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("color")) != null)
            setLineColor(new Color(Integer.parseInt(str1), true));
          else
            setLineColor(null);
        }
        else if ("MainGridLine".equals(str2))
        {
          if ((str1 = paramXMLableReader.getAttr("style")) != null)
            setMainGridStyle(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("color")) != null)
            setMainGridColor(new Color(Integer.parseInt(str1), true));
          else
            setMainGridColor(null);
        }
        else if ("SecGridLine".equals(str2))
        {
          if ((str1 = paramXMLableReader.getAttr("style")) != null)
            setSecondGridStyle(Integer.parseInt(str1));
          if ((str1 = paramXMLableReader.getAttr("color")) != null)
            setSecondGridColor(new Color(Integer.parseInt(str1), true));
          else
            setSecondGridColor(null);
        }
        else if ("TextAttr".equals(str2))
        {
          setTextAttr((TextAttr)paramXMLableReader.readXMLObject(new TextAttr()));
        }
        else if (str2.equals("Format"))
        {
          setFormat(ReportXMLUtils.readFormat(paramXMLableReader));
        }
        else if (str2.equals("ArrowShow"))
        {
          if ((str1 = paramXMLableReader.getAttr("arrowShow")) != null)
            setArrowShow(Boolean.valueOf(str1).booleanValue());
        }
        else if (str2.equals("AxisShow"))
        {
          if ((str1 = paramXMLableReader.getAttr("axisShow")) != null)
            setAxisShow(Boolean.valueOf(str1).booleanValue());
        }
        else if (str2.equals("Stagger"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
            setIsStagger(Boolean.valueOf(str1).booleanValue());
        }
        else if (str2.equals("AxisPosition"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
            setPosition(Integer.valueOf(str1).intValue());
        }
        else if (str2.equals("AxisLabelPosition"))
        {
          if ((str1 = paramXMLableReader.getAttr("value")) != null)
            setAxisLabelPosition(Integer.valueOf(str1).intValue());
        }
        else if (str2.equals("AxisRange"))
        {
          if ((str1 = paramXMLableReader.getAttr("minValue")) != null)
          {
            setCustomMinValue(true);
            setMinValue(Double.parseDouble(str1));
          }
          if ((str1 = paramXMLableReader.getAttr("maxValue")) != null)
          {
            setCustomMaxValue(true);
            setMaxValue(Double.parseDouble(str1));
          }
        }
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    if (getTitle() != null)
      getTitle().writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("AxisLine").attr("style", getLineStyle());
    if (getLineColor() != null)
      paramXMLPrintWriter.attr("color", getLineColor().getRGB());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("AxisPosition").attr("value", getPosition()).end();
    paramXMLPrintWriter.startTAG("AxisLabelPosition").attr("value", getAxisLabelPosition()).end();
    paramXMLPrintWriter.startTAG("MainGridLine").attr("style", getMainGridStyle());
    if (getMainGridColor() != null)
      paramXMLPrintWriter.attr("color", getMainGridColor().getRGB());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("SecGridLine").attr("style", getSecondGridStyle());
    if (getSecondGridColor() != null)
      paramXMLPrintWriter.attr("color", getSecondGridColor().getRGB());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("AxisLabelCount").attr("value", getLabelNumber()).end();
    paramXMLPrintWriter.startTAG("TickLine").attr("type", getTickMarkType()).attr("mainStroke", getMainStroke()).attr("len", getTickLength()).attr("secType", getSecTickMarkType()).attr("secStroke", getSecStroke()).attr("secLen", getSecTickLength()).end();
    paramXMLPrintWriter.startTAG("ArrowShow").attr("arrowShow", isArrowShow()).end();
    paramXMLPrintWriter.startTAG("AxisShow").attr("axisShow", isAxisShow()).end();
    paramXMLPrintWriter.startTAG("Stagger").attr("value", isStagger()).end();
    if (getTextAttr() != null)
      getTextAttr().writeXML(paramXMLPrintWriter);
    if (getFormat() != null)
      ReportXMLUtils.writeFormat(paramXMLPrintWriter, getFormat());
    paramXMLPrintWriter.startTAG("AxisRange");
    if (isCustomMinValue())
      paramXMLPrintWriter.attr("minValue", getMinValue());
    if (isCustomMaxValue())
      paramXMLPrintWriter.attr("maxValue", getMaxValue());
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Axis))
      return false;
    Axis localAxis = (Axis)paramObject;
    if (localAxis.getTickMarkType() != getTickMarkType())
      return false;
    if (localAxis.getTickLength() != getTickLength())
      return false;
    if (localAxis.getMainStroke() != getMainStroke())
      return false;
    if (localAxis.getSecTickMarkType() != getSecTickMarkType())
      return false;
    if (localAxis.getSecTickLength() != getSecTickLength())
      return false;
    if (localAxis.getSecStroke() != getSecStroke())
      return false;
    if (localAxis.getPosition() != getPosition())
      return false;
    if (localAxis.getMainGridStyle() != getMainGridStyle())
      return false;
    if (localAxis.getSecondGridStyle() != getSecondGridStyle())
      return false;
    if (!(Equals.equals(localAxis.getMainGridColor(), getMainGridColor())))
      return false;
    if (!(Equals.equals(localAxis.getSecondGridColor(), getSecondGridColor())))
      return false;
    if (localAxis.getLineStyle() != getLineStyle())
      return false;
    if (!(Equals.equals(localAxis.getLineColor(), getLineColor())))
      return false;
    if (!(Equals.equals(localAxis.getTextAttr(), getTextAttr())))
      return false;
    if (!(Equals.equals(localAxis.getFormat(), getFormat())))
      return false;
    if (localAxis.isStagger() != isStagger())
      return false;
    if (localAxis.getLabelNumber() != getLabelNumber())
      return false;
    if (localAxis.getAxisLabelPosition() != getAxisLabelPosition())
      return false;
    if (!(Equals.equals(localAxis.getTitle(), getTitle())))
      return false;
    if (localAxis.isArrowShow() != isArrowShow())
      return false;
    if (localAxis.isAxisShow() != isAxisShow())
      return false;
    if (localAxis.getMaxValue() != getMaxValue())
      return false;
    if (localAxis.getMinValue() != getMinValue())
      return false;
    if (localAxis.isCustomMaxValue() != isCustomMaxValue())
      return false;
    return (localAxis.isCustomMinValue() == isCustomMinValue());
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("axisLabelPosition", this.axisLabelPosition);
    localJSONObject.put("isStagger", this.isStagger);
    localJSONObject.put("labelNumber", this.labelNumber);
    localJSONObject.put("lineStyle", this.lineStyle);
    localJSONObject.put("mainGridStyle", this.mainGridStyle);
    localJSONObject.put("position", this.position);
    localJSONObject.put("secondGridStyle", this.secondGridStyle);
    localJSONObject.put("secTickLength", this.secTickLength);
    localJSONObject.put("secTickMarkType", this.secTickMarkType);
    localJSONObject.put("tickLength", this.tickLength);
    localJSONObject.put("tickMarkType", this.tickMarkType);
    if (this.format != null)
      localJSONObject.put("format", ChartUtils.format2JS(this.format));
    if (this.lineColor != null)
      localJSONObject.put("lineColor", ChartUtils.color2JS(this.lineColor));
    if (this.mainGridColor != null)
      localJSONObject.put("mainGridColor", ChartUtils.color2JS(this.mainGridColor));
    localJSONObject.put("mainStroke", this.mainStroke);
    if (this.secondGridColor != null)
      localJSONObject.put("secondGridColor", ChartUtils.color2JS(this.secondGridColor));
    localJSONObject.put("secStroke", this.secStroke);
    if (this.textAttr != null)
      localJSONObject.put("textAttr", this.textAttr.toJSONObject());
    if (this.title != null)
      localJSONObject.put("title", this.title.toJSONObject());
    localJSONObject.put("isArrowShow", this.isArrowShow);
    localJSONObject.put("isAxisShow", this.isAxisShow);
    localJSONObject.put("isCustomMinValue", isCustomMinValue());
    localJSONObject.put("minValue", getMinValue());
    localJSONObject.put("isCustomMaxValue", isCustomMaxValue());
    localJSONObject.put("maxValue", getMaxValue());
    return localJSONObject;
  }
}